﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ProjectMigrator;

namespace ProjectMigrator
{
    public partial class CodeConversion
    {
        public ConversionItemCollection PopulateConversionItems()
        {
            var conversionItems = new ConversionItemCollection
               {
                   //
                   // MainKeywords
                   //
                   new ConversionItem("using Microsoft.Crm.Sdk;", "using Microsoft.Xrm.Sdk;", true, false),
                   new ConversionItem("using Microsoft.Crm.Sdk.Metadata;", "Microsoft.Xrm.Sdk.Metadata;", true, false),
                   new ConversionItem("using Microsoft.Crm.Sdk.Metadata.Query;", "using Microsoft.Xrm.Sdk.Metadata.Query;", true, false),
                   new ConversionItem("using Microsoft.Crm.Sdk.Query;", "using Microsoft.Xrm.Sdk.Query;", true, false),
                   new ConversionItem("using Microsoft.Crm.SdkTypeProxy;", "using Microsoft.Xrm.Sdk.Messages;", true, false), 
                   new ConversionItem("using Microsoft.Crm.SdkTypeProxy.Metadata;", "//using Microsoft.Crm.SdkTypeProxy.Metadata;", true, false),
                   new ConversionItem("ICrmService", "IOrganizationService", true, false),
                   new ConversionItem("CrmService", "OrganizationService", true, false),
                   new ConversionItem("ReturnDynamicEntities = true", "", true, false),
                   new ConversionItem("BusinessEntityCollection", "EntityCollection", true, false),
                   new ConversionItem("BusinessEntity", "Entity", true, false),
                   new ConversionItem(".BusinessEntities", ".Entities", true, false),
                   new ConversionItem(".Entities.Length", ".Entities.Count", true, false),
                   new ConversionItem("AllColumns()", "ColumnSet(true)", true, false),
                   new ConversionItem(".Properties.", ".Attributes.", true, false),
                   new ConversionItem(".Properties[", ".Attributes[", true, false),
                   new ConversionItem("statecode.formattedvalue", "FormattedValues[\"statuscode\"]", true, false),
                   new ConversionItem("ownerid", "OwnerId", true, false),
                   new ConversionItem(".name", ".Name", true, false),
                   new ConversionItem("Accountid.Value", "AccountId", true, false),
                   new ConversionItem("activityparty", "ActivityParty", true, false),
                   new ConversionItem("partyid", "PartyId", true, false),
                   new ConversionItem(".productnumber", ".ProductNumber", true, false),
                   new ConversionItem(".relationshiprole", ".RelationshipRole", true, false),

                   //
                   // CrmDataTypes
                   //
                    new ConversionItem("CrmTypes.CreateCustomer", "new EntityReference", false, false),
                    new ConversionItem("CrmTypes.CreateLookup", "new EntityReference", true, false),
                    new ConversionItem("CrmTypes.CreateOwner", "new EntityReference", true, false),
                    new ConversionItem("CrmTypes.CreateCrmMoney", "new Money", true, false),
                    new ConversionItem("CrmMoneyProperty", "Money", true, false),
                    new ConversionItem("CrmTypes.CreatePicklist", "new OptionSetValue", true, false),
                    new ConversionItem("CrmTypes.CreateStatus", "new OptionSetValue", true, false),
                    new ConversionItem("DynamicEntity", "Entity", true, false),
                    new ConversionItem("Picklist", "OptionSetValue", true, false),
                    new ConversionItem("Customer", "EntityReference", true, false),
                    new ConversionItem("Lookup", "EntityReference", true, false),
                    new ConversionItem("Moniker", "EntityReference", true, false),

                    // RegEx queries
                    new ConversionItem(@"CrmTypes.CreateCrmDateTimeFromUser\((.+)\)", @"$1", true, true),
                    new ConversionItem(@"CrmTypes.CreateCrmNumber\((.+)\)", "$1", false, true),
                    new ConversionItem(@"CrmTypes.CreateCrmDateTime\((.+)\)", @"$1", true, true),
                    new ConversionItem(@"CrmTypes.CreateCrmBoolean\((.+)\)", @"$1", false, true),
                    new ConversionItem(@"CrmTypes.CreateKey\((.+)\)", @"$1", false, true),
                    new ConversionItem(@"CrmTypes.CreateCrmDecimal\((.+)\)", @"$1", false, true),
                    new ConversionItem(@"CrmTypes.CreateCrmFloat\((.+)\)", @"$1", false, true),
                    new ConversionItem(@"CrmTypes.CreateGuid\((.+)\)", @"new Guid\($1\)", false, true),
                    new ConversionItem(@"new CrmNumber\((.+)\)", @"$1", false, true),
                    new ConversionItem(@"new CrmBoolean\((.+)\)", @"$1", false, true),
                    new ConversionItem(@"new CrmDecimal\((.+)\)", @"$1", false, true),
                    new ConversionItem(@"new CrmDouble\((.+)\)", @"$1", false, true),
                    new ConversionItem(@"new CrmFloat\((.+)\)", @"$1", false, true),
               };

            return conversionItems;
        }
    }
}
